//
//
//
//

#import "TableQcStandard.h" 

@implementation TableQcStandard

-(NSMutableArray *) TransalteToModel:(FMResultSet*) set{
    
    NSMutableArray *array = [NSMutableArray array];
    while ([set next]) {
        HQc_standardModel *model = [[HQc_standardModel alloc]init];
        model.STANDARD_ID = [set stringForColumn:@"standard_id"];
        model.STANDARD_NAME = [set stringForColumn:@"standard_name"];
        model.INPUT_CODE1 = [set stringForColumn:@"input_code1"];
        model.ORDER_NUM = [set stringForColumn:@"order_num"];
        model.TYPE_ID = [set stringForColumn:@"type_id"];
        [array addObject:model];
    }
    
    return array;
}


-(NSMutableArray *) TransalteTypeToModel:(FMResultSet*) set{
    
    NSMutableArray *array = [NSMutableArray array];
    while ([set next]) {
        HQcTypeModel *model = [[HQcTypeModel alloc]init];
        model.TYPE_ID = [set stringForColumn:@"type_id"];
        model.TYPE_NAME = [set stringForColumn:@"type_name"];
        model.ORDER_NUM = [set stringForColumn:@"order_num"];
        model.INPUT_CODE1 = [set stringForColumn:@"input_code1"];
        [array addObject:model];
    }
    
    return array;
}

-(NSMutableArray *) TransalteToHcodeModel:(FMResultSet*) set{
    
    NSMutableArray *array = [NSMutableArray array];
    while ([set next]) {
        HQc_codeModel *model = [[HQc_codeModel alloc]init];
        model.CODE_ID = [set stringForColumn:@"code_id"];
        model.TYPE_ID = [set stringForColumn:@"type_id"];
        model.STANDARD_ID = [set stringForColumn:@"standard_id"];
        model.CODE_NAME = [set stringForColumn:@"code_name"];
        model.PAR_ID = [set stringForColumn:@"par_id"];
        model.END_FLAG = [set stringForColumn:@"end_flag"];
        model.LEVELS = [set stringForColumn:@"levels"];
        model.SCORE = [set stringForColumn:@"score"];
        model.STANDARD_SCORE = [set stringForColumn:@"standard_score"];
        model.WEIGHTS = [set stringForColumn:@"weights"];
        model.INSPECTION_METHOD = [set stringForColumn:@"inspection_method"];
        model.SCORE_METHOD = [set stringForColumn:@"score_method"];
        model.OTHERHELP = [set stringForColumn:@"otherhelp"];
        model.ORDER_NUM = [set stringForColumn:@"order_num"];
        model.SHOW_FRAME = [set stringForColumn:@"show_frame"];
        model.PROBLEM_COLLECTION_FLAG = [set stringForColumn:@"problem_collection_flag"];
        model.KEYCODE_FLAG = [set stringForColumn:@"keycode_flag"];
        [array addObject:model];
    }
    
    return array;
}



- (NSMutableArray *)GetQcStandardWithType_id:(NSString *)type_id{
    
    [DBHelper.DB open];
    
    NSString* sql = [NSString stringWithFormat:@"select * from hr_ns_checkstandard where 1 = 1 AND type_id = '%@'",type_id];
    
    NSString *order = @" %@ order by input_code1 asc";
    
    sql = [NSString stringWithFormat:order,sql];
    
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    
    NSMutableArray *array = [self TransalteToModel:set];
    
    [DBHelper.DB close];
    return array;
    
    
}

-(NSMutableArray *) GetQcTypeWithType_id:(NSString *)type_id
{
    [DBHelper.DB open];
    
    NSString* sql = [NSString stringWithFormat:@"select * from hr_ns_checktype where 1 = 1 AND type_id = '%@'",type_id];
    
    NSString *order = @" %@ order by input_code1 asc";
    
    sql = [NSString stringWithFormat:order,sql];
    
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    
    NSMutableArray *array = [self TransalteTypeToModel:set];
    
    
    [DBHelper.DB close];
    return array;

}

- (NSMutableArray *)GetHnightQuality:(NSString *)standard_id
{
    [DBHelper.DB open];
    
    NSString* sql = [NSString stringWithFormat:@"select * from hr_ns_checkcode where  standard_id = '%@'",standard_id];
    
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    
    NSMutableArray *array = [self TransalteToHcodeModel:set];
    [DBHelper.DB close];
    return array;

}

- (NSArray *) GetQcCodeWithStandardId:(NSString *)standard_id
{
    [DBHelper.DB open];
    
    NSString* sql = [NSString stringWithFormat:@"select * from hr_ns_checkcode where  standard_id = '%@'",standard_id];
    sql = [NSString stringWithFormat:@"%@ order by code_id asc",sql];
    
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    
    NSMutableArray *array = [self TransalteToHcodeModel:set];
    [DBHelper.DB close];
    return array;
    
}

- (NSArray *) GetQcCodeWithParentId:(NSString *)standard_id parent_id: (NSString *)parent_id{
    [DBHelper.DB open];
    
    NSString* sql = [NSString stringWithFormat:@"select * from hr_ns_checkcode where  standard_id = '%@'",standard_id];
    sql = [NSString stringWithFormat:@"%@ and par_id = '%@' ",sql , parent_id];
    sql = [NSString stringWithFormat:@"%@ order by code_id asc",sql];
    
    FMResultSet *set = [DBHelper.DB executeQuery:sql];
    
    NSMutableArray *array = [self TransalteToHcodeModel:set];
    [DBHelper.DB close];
    return array;
}


@end
